<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="源文件名">
              <a-input placeholder="" v-model="queryParam.name"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-button @click="() => {this.queryPage()}" type="primary">查询</a-button>
            <a-button @click="() => queryParam = {}" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <v-table
      ref="table"
      :data="loadData"
      :columns="tableObj.columns"
    >
      <template v-slot:buttons>
        <a-button @click="$refs.fileUpload.init()" icon="plus" type="primary">上传文件</a-button>
      </template>
      <span slot="avatar" slot-scope="{text, row}">
        <a-avatar
          size="large"
          :src="row.url"
          v-if="row.type === 'image/png' || row.type === 'image/jpeg' "
        />
        <a-avatar size="large" icon="user" v-else/>
      </span>
      <span slot="action" slot-scope="{text, row}">
        <span v-action="'sys:client:update'">
          <a :href="row.url" download>下载</a>
        </span>
      </span>
    </v-table>
    <file-upload
      ref="fileUpload"
      @ok="queryPage"
    />

  </a-card>
</template>

<script>
import { TableMixin } from '@/mixins/TableMixin'
import { fetchList } from '@/api/file'
import FileUpload from './FileUpload'
import { tableObj } from './template'
export default {
  name: 'Index',
  mixins: [TableMixin],
  components: {
    FileUpload
  },
  data () {
    return {
      tableObj,
      queryParam: {
        name: ''
      },
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
